import cv2
import matplotlib.pyplot as plt
import numpy as np
import math

# 读取图像
img1 = cv2.imread("blossom.jpeg")

# 图像旋转
h, w = img1.shape[:2]
M = np.float32([[math.cos(math.pi/4), -math.sin(math.pi/4), 0], [math.sin(math.pi/4), math.cos(math.pi/4), 0]]) # 顺时针旋转45°
dst = cv2.warpAffine(img1, M, (w, h))

# 图像显示
fig, axes = plt.subplots(1, 2, figsize=(10, 8), dpi=100)
axes[0].imshow(img1[:, :, ::-1])
axes[0].set_title("original")
axes[1].imshow(dst[:, :, ::-1])
axes[1].set_title("after rotation")

plt.show()